<?php

include_once(dirname(__FILE__) . "../../_DATABASE_DAO/GenericDAO.class.php");
include_once(dirname(__FILE__) . "../../_DATABASE_DAO/LookupsDAO.class.php");

$genericDAO = new GenericDAO();
$lookupDao = new LookupsDAO();

if ($_REQUEST['action'] == 'view') {
    $datas = $genericDAO->listAll("privileges");
    foreach ($datas as $data) {
        $data->type = $genericDAO->get("privilegesType", $data->typeId);
    }
    include('views/privileges/home.php');
    exit;
}
if ($_REQUEST['action'] == 'save') {
    $id = "";
    if (isset($_REQUEST['id'])) {
        $id = $_REQUEST['id'];
        $lookup = $genericDAO->edit("privileges", $_POST, "id = " . $id);
    } else {
        $id = $genericDAO->save("privileges", $_POST);
    }

    $datas = $genericDAO->listAll("privileges");
    foreach ($datas as $data) {
        $data->type = $genericDAO->get("privilegesType", $data->typeId);
    }
    include('views/privileges/home.php');
    exit;
}
if ($_REQUEST['action'] == 'create') {
    if (isset($_REQUEST['id']))
        $datas = $genericDAO->get("privileges", $_REQUEST['id']);
    $types = $genericDAO->listAll("privilegesType");
    include ("views/privileges/form.php");
    exit;
}

if ($_REQUEST['action'] == 'delete') {
    if (isset($_REQUEST['id']))
        $lookupDao->Delete("privileges", ($_REQUEST['delState'] + 1) % 2, $_REQUEST['id']);
    $datas = $genericDAO->listAll($_REQUEST['module']);
    include('views/privileges/home.php');
    exit;
}
?>
